import Vue from 'vue'
import Cookies from 'js-cookie'
import formMaker from './components/form-making/index'
import 'normalize.css/normalize.css' // a modern alternative to CSS resets

import Element from 'element-ui'
import './utils/directives.js'
import './styles/element-variables.scss'

import '@/styles/index.scss' // global css

import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/index.css'

import App from './App'
import store from './store'
import router from './router'
import lodash from 'lodash'
import dicManager from '@/utils/dicMap'
import i18n from './lang' // internationalization
import './icons' // icon
import './permission' // permission control
import './utils/error-log' // error log
//import 'babel-polyfill'
// 导出报表工具类
import exportexcel from './utils/exportExcel'

import * as filters from './filters' // global filters
import common from './utils/common'

// if (process.env.NODE_ENV === 'production') {
//   const {mockXHR} = require('../mock')
//   mockXHR()
// }
Vue.use(VXETable)
Vue.prototype.$_ = lodash
import Contextmenu from '@/components/vue-contextmenujs'
import resize from './components/Charts/mixins/resize'
import {data} from 'jquery'

Vue.use(Contextmenu)
import VueEditor from "vue2-editor"

Vue.use(VueEditor)
Vue.prototype.$_ = lodash


import Kingwolfofsky from './utils/kingwolfofsky'
Vue.prototype.$kingwolfofsky = Kingwolfofsky

Vue.use(Element, {
  size: Cookies.get('size') || 'medium', // set element-ui default size
  i18n: (key, value) => i18n.t(key, value)
})
Vue.use(formMaker, {i18n: (key, value) => i18n.t(key, value)})

// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false
Vue.prototype.subsysinfo = common.subsysinfo
Vue.prototype.winMenuForMenu = {winkey: null}
Vue.prototype.baseHttpurl = common.baseHttpurl
Vue.prototype.$exportexcel = exportexcel
Vue.prototype.$dicManager = dicManager;
new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App),
  baseHttpurl: common.baseHttpurl,
  created() {
    let $t = this;
    window.onresize = function () {
      $t.$store.dispatch("business/setValue", {root: 'windowresize', key: 'resize', value: new Date()})
    }
  }
})

VXETable.renderer.add('elButton', {
  renderDefault (h, renderOpts, params) {
    let { row, column } = params
    let { events } = renderOpts
    return [
      <el-button size="mini" onClick={ () => events.click(params.row) }>{renderOpts.value}</el-button>
    ]
  },
})

// vxe-grid 自定义渲染器

VXETable.renderer.add('mutiButtons', {
  renderDefault(h, renderOpts, params) {
    let {row, column} = params
    let { events } = renderOpts
    return [
      <muti-buttons renderOpts={renderOpts} row={params.row} ></muti-buttons>
    ]
  }
})
